package com.hunt.service.impl;

import com.hunt.dao.StockFlowMapper;
import com.hunt.model.entity.StockFlow;
import com.hunt.model.entity.StockFlowName;
import com.hunt.model.entity.StockFlowNameNew;
import com.hunt.model.entity.StockFlowNew;
import com.hunt.service.StockFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class StockFlowServiceImpl implements StockFlowService {

    @Autowired
    private StockFlowMapper stockFlowMapper;

    @Override
    public StockFlow findByStockCode(String stockCode) {
        StockFlow stockflow = null;
        stockflow = stockFlowMapper.findByStockCode(stockCode);
        if (stockflow != null) {
            StockFlowName stockFlowName = stockFlowMapper.findName();
            stockflow.setQuarterL1(stockFlowName.getL1name());
            stockflow.setQuarterL2(stockFlowName.getL2name());
            stockflow.setQuarterL3(stockFlowName.getL3name());
            stockflow.setQuarterL4(stockFlowName.getL4name());


            return stockflow;
        } else {
            stockflow = new StockFlow();
            StockFlowName stockFlowName = stockFlowMapper.findName();
            stockflow.setQuarterL1(stockFlowName.getL1name());
            stockflow.setQuarterL2(stockFlowName.getL2name());
            stockflow.setQuarterL3(stockFlowName.getL3name());
            stockflow.setQuarterL4(stockFlowName.getL4name());
            return stockflow;
        }


    }

    /*--
    新的接口由四个季度变为八个季度
     */
    @Override
    public StockFlowNew findByStockCodeNew(String stockCode) {
        StockFlowNew stockflow = null;
        stockflow = stockFlowMapper.findByStockCodeNew(stockCode);
        if (stockflow != null) {
            StockFlowNameNew stockFlowName = stockFlowMapper.findNameNew();
            stockflow.setQuarterL1(stockFlowName.getL1name());
            stockflow.setQuarterL2(stockFlowName.getL2name());
            stockflow.setQuarterL3(stockFlowName.getL3name());
            stockflow.setQuarterL4(stockFlowName.getL4name());
            stockflow.setQuarterL5(stockFlowName.getL5name());
            stockflow.setQuarterL6(stockFlowName.getL6name());
            stockflow.setQuarterL7(stockFlowName.getL7name());
            stockflow.setQuarterL8(stockFlowName.getL8name());


            return stockflow;
        } else {
            stockflow = new StockFlowNew();
            StockFlowNameNew stockFlowName = stockFlowMapper.findNameNew();
            stockflow.setQuarterL1(stockFlowName.getL1name());
            stockflow.setQuarterL2(stockFlowName.getL2name());
            stockflow.setQuarterL3(stockFlowName.getL3name());
            stockflow.setQuarterL4(stockFlowName.getL4name());
            stockflow.setQuarterL5(stockFlowName.getL5name());
            stockflow.setQuarterL6(stockFlowName.getL6name());
            stockflow.setQuarterL7(stockFlowName.getL7name());
            stockflow.setQuarterL8(stockFlowName.getL8name());
            return stockflow;
        }
    }

}
